<?php
class tpl_list {
	function call($toObj) {
		$objTable = $toObj->DOG_appendChild('table')->addClass('list');
		$objThead = $objTable->DOG_appendChild('thead');
		$objTr = $objThead->DOG_appendChild('tr');

		$cntCol = 0;

		foreach ($ListItems = (array)Y('Module.List.Editor.YML', 'validate') as $Key=>$ListItem) {
			if (empty($ListItem['list']) || !strcasecmp($ListItem['list'], "no")) continue;

			$objTh = $objTr->DOG_appendChild('th');
			if (!strcasecmp($ListItem['list'], "information")) $objTh->addClass('Information');
			$objTh->text((isset($ListItem['string']))?($ListItem['string']):($Key)); 
					$cntCol++;
		}

		$objTbody = $objTable->DOG_appendChild('tbody');

		$cntData = 0;
		if ($Data = Y('Module.List.Editor.Data')) {
			foreach ($Data as $Item) {
				$isLoop = 0;
				$objTr = $objTbody->DOG_appendChild('tr');
				foreach ($ListItems as $Key=>$ListItem) {
					if (empty($ListItem['list']) || !strcasecmp($ListItem['list'], "no")) continue;

					$objTd = $objTr->DOG_appendChild('td');
					if (!strcasecmp($ListItem['list'], "information")) $objTd->addClass('Information');

					if (!$isLoop) {
						$objTd = $objTd->DOG_appendChild('a')->attr(array(
							'href' => Y('Route.Path').'/'.Y('Module.List.Editor.YML', 'baseurl').'/edit/'.$Item['ID'],
							'class'=> 'First'
						));
					}
					// このへんからデータ型ごとの処理
					$Type = strtolower ($ListItem['type']);
					switch ($Type){
						case ('utimestamp'):
						case ('date'):
							$objTd->text(date('Y/m/d H:i:s', $Item[$Key]));
							break;
						default:
							break;
					}

					// このへんからフォーム型ごとの処理
					$Form = strtolower ($ListItem['form']);
					switch ($Form){
						case ('radio'):
							$objTd->text($ListItem['option'][$Item[$Key]]);
							break;
						default:
							break;
					}

					if (!$objTd->text()){
						if ($Item[$Key]) $objTd->text($Item[$Key]);
						else $objTd->text('-');
					}
					$isLoop++;
				}
				$cntData++;
			}
		} else {
			 $objTbody->DOG_appendChild('tr')->DOG_appendChild('td')->attr(array('colspan'=>$cntCol))->text('一覧がありません');
		}

		$objTable->DOG_appendChild('tfoot')->DOG_appendChild('tr')->DOG_appendChild('th')->attr(array('colspan'=>$cntCol+1))->text('&nbsp;');
	}
}
?>